package com.itboye.jmsfhz.widget;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
/**
 * @since 2016-05-10
 * @author 自定义Toast可以再Toast中添加一张图片
 * @author liutian
 * @author 不用.show
 *
 */
public class ToastUtil {
	
	 public static void myTosat(Context context , int imageId ,String content , int duration){
	        //new一个toast传入要显示的activity的上下文
	        Toast toast = new Toast(context);
	        //显示的时间
	        toast.setDuration(duration);
	        //显示的位置
	        toast.setGravity(Gravity.BOTTOM, 0, 300);
	        //重新给toast进行布局
	        LinearLayout toastLayout = new LinearLayout(context);
	        toastLayout.setOrientation(LinearLayout.HORIZONTAL);
	        toastLayout.setGravity(Gravity.CENTER_VERTICAL);
	       
	        ImageView imageView = new ImageView(context);
	        imageView.setImageResource(imageId);
	        //把imageView添加到toastLayout的布局当中
	        toastLayout.addView(imageView);
	       
	        TextView textView = new TextView(context);
	        textView.setText(content);
//	        textView.setBackgroundColor(Color.GRAY);
	        //把textView添加到toastLayout的布局当中
	        toastLayout.addView(textView);
	        toastLayout.setBackgroundColor(Color.GRAY);
	        //把toastLayout添加到toast的布局当中
	        toast.setView(toastLayout);
	        toast.show();
	    }
}
